package com.coms514.scheduleme;

import java.io.IOException;

import com.google.api.services.calendar.model.Event;

/**
 * Asynchronously insert a new event.
 * 
 * @author Qilin Li
 */
public class AsyncUpdateEvent extends EventsAsyncTask {

	/**
	 * @param args
	 */
	  private final String calendarId;
	  private final EventInfo eventInfo;

	  AsyncUpdateEvent(ShowEventsActivity activity, String calendarId, EventInfo eventInfo) {
	    super(activity);
	    this.calendarId = calendarId;
	    this.eventInfo = eventInfo;
	  }

	  @Override
	  protected void doInBackground() throws IOException {
		  //FIXME: err happens sometimes when using update() method
		//Event updatedEvent = client.events().update(calendarId, eventInfo.id, eventInfo.createEvent()).execute();
		  client.events().delete(calendarId, eventInfo.id).execute();
		  model.remove(eventInfo);
		  Event updatedEvent = client.events().insert(calendarId, eventInfo.createEvent()).execute();
		  model.add(updatedEvent);
	  }

}